<?php
// DB Created by Rich L. a member in service in Northern Delaware.  Please feel free to share this code wherever it may be useful to alcholoics.  Should you have questons please contact me at sobernerd@gmail.com
//header items
$jQuery = true;
$tinyMCE = true;
$jQueryCookie = true;
$hoverIntent = true;
$Jededitable = true;
$sectionSort = true;
$googleAPI = false;
$calendar = false;
//end header items
$pageTitle = 'Soberpress - Administration - modules';
$helpKey = 'modulesForm';
$editdate = date("Y-m-d G:i:s");  
require_once ('../../config/include_paths.php');
require_once('config.php');
require_once('functions.php');
require_once('dbconnect.php');	// database connect script.
session_start();

if ($_SESSION['logged_in'] == 0) {
	require ('security_check.php');
} else {
		// Get form information if editing
		if (ifsetor($_GET['id'])) 
		{
			$sql = "SELECT * FROM modules WHERE id='".$_GET['id']."'";
					
			$result =  mysql_query($sql)
			or die(mysql_error());
			
			// Get each row of data on each iteration until
			// there is no more rows
			while ($row = mysql_fetch_assoc($result)) {
				$id = $row['id'];
				$page_id = $row['page_id'];
				$section_id = $row['section_id'];
				$record_order = $row['record_order'];
				$system_module = $row['system_module'];
				$title = $row['title'];
				$editHTML = $row['editHTML'];
				$file = $row['file'];
				$lasteditor = $row['editor'];	
				$editdate = $row['editdate'];
			}
		  }
// get modules for section sorted
if (ifsetor($_GET['page_id'])) {$page_id = $_GET['page_id'];}
if ($page_id == '') $page_id = 1;
$query  = "SELECT * FROM modules
			WHERE page_id = $page_id and enabled = 1
			ORDER BY record_order ASC";
	$moduleresult = mysql_query($query);	
require_once ('adminhead.php');
?>
<body onLoad="checkMenuSettings(); loadTinyMCE();">
<div id="wrapper">
    <?php require_once ('adminHeader.php'); ?>
  <div class="clearfloat">&nbsp;</div>
  <div id="sidebar">
   <?php require_once ('adminNav.php'); ?>
  </div>
  <div id="main_content">
  <?php if ($system_module == 'aaOnlineResources') {
	  require ('aaOnlineResources.php');
  } else if ($system_module == 'meetingResources') {
	  require ('meetingResources.php');
  } else { ?>
    <form id="htmlEditor" action="processForm.php" method="post" name="htmlEditor" enctype="multipart/form-data">
      <table>
        <tr>
          <td width="82" class="tdRight">Module Title:</td>
          <td colspan="8" class="tdLeft">
              <input name="title" id="title" type="text" size="50" value="<?php echo $title?>" class="colorInput">
          </td>
        </tr>
         <tr>
          <td class="tdRight">Section:</td>
          <td width="87" class="tdLeft">
              <select name="page_id" id="page_id">
              	<option value="1" <?php if ($page_id == 1) echo 'selected' ?>>Home</option>
                <option value="2" <?php if ($page_id == 2) echo 'selected' ?>>News</option>
                <option value="4" <?php if ($page_id == 4) echo 'selected' ?>>Contacts</option>
              </select>
          </td>
          <?php if (!$id) {?>
          <td width="35" class="tdRight">Sort:</td>
          <td width="115" class="tdLeft">
       		  	<label><input type="radio" name="sortChoice" value="1" id="sortChoice_0"> Top of Section</label>
          </td>
          <td width="137" class="tdLeft">
             	<label><input type="radio" name="sortChoice" value="lastItem" id="sortChoice_1"> Bottom of Section</label>
          </td>
          <td width="62" class="tdLeft">
             	<label><input type="radio" name="sortChoice" value="after" id="sortChoice_2"> After:</label>
          </td>
          <td width="49" class="tdLeft">
				<select name="sortSelect" id="sortSelect">
                <?php while($modulerow = mysql_fetch_array($moduleresult, MYSQL_ASSOC))
					{ echo '<option value='.$modulerow['record_order'].'>'.$modulerow['title'].'</option>'; 
                    }?>
              	</select>
          </td>
          <?php }?>
        </tr>
        <tr>
          <td bgcolor="#feffff" colspan="8" class="tdLeft">
              <textarea id='editHTML' name='editHTML' rows='20' cols='80'><?php echo $editHTML ?></textarea>
          </td>
        </tr>
        <tr>
          <td class="tdRight">File:</td>
          <td colspan="7" class="tdLeft">
          		<?php if($id){
                 echo   "<span id='currentFile'>$file</span>&nbsp;&nbsp;<input name='changeFile' id='changeFile' type='button'
				 		 value='Change-Upload File'>";
                     } else { 
            	 echo  "<input id='file' name='file' type='file' class='colorInput'/>";
              		 } ?>
          </td>
        </tr>
        <tr>
        <td colspan="8" style="line-height:1.5em;">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="3"></td><td class="tdCenter"><input type="submit" name="submit" value="Submit" class="groovybutton" /></td>
          <td  colspan="5" class="tdLeft"><input type="reset" class="groovybutton"/></td>
        </tr>
        <tr>
        <td colspan="8" style="line-height:1.5em;">&nbsp;</td>
        </tr>
        <?php
	//if admin display last editor and date
	if ($_SESSION['admin'] == 1) {
	/* format date for display */
				$current_editdate = strtotime($editdate);
				$displaydate = date('Y-m-d G:i:s', $current_editdate);							
	echo "<tr>
			<td align =\"right\"><strong>Last Editor:</strong></td><td>$lasteditor</td>
			<td nowrap =\"nowrap\" align =\"right\"><strong>Last Edit Date/Time:&nbsp;</strong></td><td>$displaydate</td>
		  </tr>";  } ?>
        <input type="hidden" name="editor" value="<?php echo $_SESSION['username'] ?>" />
        <input type="hidden" name="id" value="<?php echo $id ?>" />
        <input type="hidden" name="tableID" value="modules" />
        <input type="hidden" name="currentFile" id="currentFile" value="<?php echo $file ?>" />
       </table>
    </form>
    <?php } ?>
  </div>
</div>
</div>
</body>
</div>
</div>
<?php mysql_close($conn);} ?>
</body>
</html>